package com.oraro.paygatewaybiz.proxy;

import com.oraro.common.result.Result;
import com.oraro.paygatewaybiz.constant.Constants;
import com.oraro.paygatewaybiz.interfaces.PayChannelService;
import com.oraro.paygatewaybiz.module.entity.ChannelEntity;
import com.oraro.paygatewaybiz.module.entity.OrderEntity;
import com.oraro.paygatewaybiz.module.service.OrderService;
import com.oraro.plugin.proxy.OraroServiceProxyPluginManager;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * @Author: jianghuiyong
 * @Date: 2018/11/15 21:03
 * @Version 1.0
 */
@Service
public class PayChannelServiceProxy extends OraroServiceProxyPluginManager<PayChannelService> implements  PayChannelService{

    @Autowired
    private OrderService orderService;
    @Override
    public String type() {
        return Constants.ProxyType.CHANNELPROXY.getType();
    }

    @Override
    public Result payOrder(OrderEntity orderEntity, ChannelEntity channelEntity) {
        PayChannelService payChannelService = selectPlugin(getParam(channelEntity.getChannelType()));
        return payChannelService.payOrder(orderEntity, channelEntity);
    }

    @Override
    public String handleNotify(Map<String, String> result, String channelType) {
        PayChannelService payChannelService = selectPlugin(getParam(channelType));
        return payChannelService.handleNotify(result, channelType);
    }

}
